package com.example.xmind2testcase.service;

import com.example.xmind2testcase.mapper.ProjectMapper;
import com.example.xmind2testcase.mapper.TestPlainMapper;
import com.example.xmind2testcase.pojo.Project;
import com.example.xmind2testcase.pojo.TestPlain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProjectServiceIpml implements ProjectService{

    @Autowired
    ProjectMapper projectMapper;

    @Autowired
    TestPlainMapper testPlainMapper;

    @Override
    public List<Project> getProjectList() {
        return projectMapper.getProjects();
    }

    @Override
    public Project addProject(Project project) {
        List<Project> projects = projectMapper.queryProject(project);
        if(projects.size()!=0){
            System.out.println("存在同名项目");
        }
        projectMapper.addProject(project);

        return  projectMapper.queryProject(project).get(0);
    }

    @Override
    public TestPlain addTestPlain(TestPlain testPlain) {
       List<TestPlain> testPlains = testPlainMapper.queryTestPlain(testPlain);
        if(testPlains.size()!=0){
            System.out.println("存在相同名称的测试用例");
        }
        testPlainMapper.addTestPlain(testPlain);
       List<TestPlain> testPlains1 = testPlainMapper.queryTestPlain(testPlain);
        return testPlains1.get(0);
    }

    @Override
    public List<TestPlain> getTestPlanList(Long project) {
        TestPlain testPlain = new TestPlain();
        testPlain.setProjectId(project);
        List<TestPlain> testPlains = testPlainMapper.queryTestPlain(testPlain);
        return testPlains;
    }


}
